import babelpolyfill from "babel-polyfill";
import Vue from "vue";
import App from "./App";
import Antd from "ant-design-vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "ant-design-vue/dist/antd.css";
// import './assets/theme/theme-green/index.css'
import VueRouter from "vue-router";
import store from "./vuex/store";
import Vuex from "vuex";
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from "./routes";
// import Mock from './mock'
// Mock.bootstrap();
import "font-awesome/css/font-awesome.min.css";
import VueQuillEditor from "vue-quill-editor";
import * as Quill from "quill";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
//import G2 from '@antv/g2'
//import Dataset from '@antv/data-set'

import Menuleft from "@/components/menuItem/menuleft";
import Chart from "./components/chart";

// 引入公共样式
import "./styles/common.css";
// 引入echarts
import echarts from "echarts";
Vue.prototype.$echarts = echarts;

Vue.use(Antd);
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(VueQuillEditor);
Vue.use(Quill);
//Vue.use(G2)
//Vue.use(Dataset);

Vue.component("menuleft", Menuleft);
Vue.component("Chart", Chart);

Vue.prototype.$img = "http://oatest.douziit.com";//测试环境
// Vue.prototype.$img = "https://oa2.douziit.com"; //正式环境


Vue.filter("dateFormat", function (date) {
  var dateArr = date.split("T");
  var dateStr = dateArr.join(" ");
  return dateStr;
});

import validate from "./common/js/validate.js";
Vue.prototype.$validate = validate;
import type from "./common/js/type.js";
Vue.prototype.$type = type;
import moment from "moment";
Vue.prototype.$moment = moment;
import Viewer from "v-viewer";
import "viewerjs/dist/viewer.css";
import md5 from "js-md5";
Vue.prototype.$md5 = md5;
//Vue.use(Viewer) 默认配置写法
Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999,
  },
});
//NProgress.configure({ showSpinner: false });

// import scroll from 'vue-seamless-scroll'
// Vue.use(scroll)   //8.10 蹇婷新增插件

const router = new VueRouter({
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.matched.some((res) => res.meta.requireAuth)) {
    // 判断是否需要登录权限
    if (JSON.parse(sessionStorage.getItem("userInfo"))) {
      // 判断是否登录
      next();
    } else {
      // 没登录则跳转到登录界面
      next({
        path: "/",
        query: { redirect: to.fullPath },
      });
    }
  } else {
    next();
  }
});

Vue.directive('defaultSelect', {
  componentUpdated(el, bindings) {
    const [defaultValues] = bindings.value
    const dealStyle = function (tags) {
      // 因为不可删除原有值，所以原有值的index是不会变的，也就是将前n个tag的close隐藏掉即可。n即已有值的长度defaultValues.length
      tags.forEach((el, index) => {
        if (
          index <= defaultValues.length - 1 &&
          ![...el.classList].includes('select-tag-close-none')
        ) {
          el.style.display = 'none' // close 图标隐藏掉
        }
      })
    }
    // 设置样式隐藏close icon
    const tags = el.querySelectorAll('.el-tag__close')
    if (tags.length === 0) {
      // 初始化tags为空处理
      setTimeout(() => {
        const tagTemp = el.querySelectorAll('.el-tag__close')
        dealStyle(tagTemp)
      })
    } else {
      dealStyle(tags)
    }
  }
})

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: (h) => h(App),
}).$mount("#app");

if (module.hot) {
  module.hot.accept();
}
